package com.example.demo.encoder;

import org.springframework.security.crypto.password.PasswordEncoder;

public class MyPasswordEncoder implements PasswordEncoder {
    /**
     *密码加密方法，参数明文，返回密文
     */
    @Override
    public String encode(CharSequence rawPassword) {
        System.out.println("自定义密码解析器encode执行");
        return (String) rawPassword;
    }

    /**
     *校验密码明文和密文是否相同
     */
    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        System.out.println("自定义密码解析器matches执行");
        //先使用encode用相同加密策略加密再对比
        return encode(rawPassword).equals(encodedPassword);
    }

    /**
     *是否强化密码解析策略
     */
    @Override
    public boolean upgradeEncoding(String encodedPassword) {
        return PasswordEncoder.super.upgradeEncoding(encodedPassword);
    }
}
